<?php

require_once("functions.php");

if(!isset($_GET['id'])) {
	header("Location: index.php");
} else {
	$id=$_GET['id'];
}

$db=connectDB();
$rset=$db->query("SELECT name,avg,hcp,pins,score FROM bowlers WHERE id={$id}");
if(PEAR::isError($rset)) {
	print $rset->getMessage();
	print "<br>";
	exit();
}
$row=$rset->fetchRow();
$name=$row[0];
$average=$row[1];
$handicap=$row[2];
$pins=$row[3];
$score=$row[4];

$sql="SELECT id,date,pins,handicap,total FROM games WHERE bowler_id={$id} ORDER BY date DESC,id ASC LIMIT 10";
$rset=$db->query($sql);
if(PEAR::isError($rset)) {
	print $rset->getMessage();
	print "<br>\n";
	exit();
}
?>
<html>
<head>
<title>Bowler: <?php echo $name; ?></title>
</head>
<body>
<table cellpadding="5" cellspacing="0" border="1" width="600">
<?php
	if(checkLogin($_SERVER)) {
		print addLines($id);
	}
?>
<tr><td align="center" colspan="8" bgcolor="lightgreen" style="font-weight: bold;"><?php echo $name; ?></td></tr>
<tr>
	<td bgcolor="lightblue" align="right">Average</td>
	<td bgcolor="lightblue" align="left" style="font-weight: bold;">&nbsp;&nbsp;&nbsp;<?php echo $average;?></td>
	<td bgcolor="lightblue" align="right">Handicap</td>
	<td bgcolor="lightblue" align="left" style="font-weight: bold;">&nbsp;&nbsp;&nbsp;<?php echo $handicap;?></td>
	<td bgcolor="lightblue" align="right">Pins</td>
	<td bgcolor="lightblue" align="left" style="font-weight: bold;">&nbsp;&nbsp;&nbsp;<?php echo $pins;?></td>
	<td bgcolor="lightblue" align="right">Score</td>
	<td bgcolor="lightblue" align="left" style="font-weight: bold;">&nbsp;&nbsp;&nbsp;<?php echo $score;?></td>
</tr>
<tr><td align="center" colspan="8" bgcolor="lightgreen" style="font-weight: normal;">Games (<a href="index.php">Home</a>)</td></tr>
<tr>
	<td align="center" colspan="2" bgcolor="lightblue">Date</td>
	<td align="center" colspan="2" bgcolor="lightblue">Pins</td>
	<td align="center" colspan="2" bgcolor="lightblue">Handicap</td>
	<td align="center" colspan="2" bgcolor="lightblue">Total</td>
</tr>
<?php
while(($row=$rset->fetchRow())==true) {
	if($bg != 'yellow') {
		$bg='yellow';
	} else {
		$bg='white';
	}
	print "<tr>\n";
	$id=array_shift($row);
	foreach($row as $k=>$r) {
		if($k==0) {
			$link="<a href=\"showDate.php?date={$r}\">{$r}</a>";
			$link=$r;
			$del="<font size=\"-2\"><a href=\"deleteGame.php?id={$id}&bowler={$_GET['id']}\">[x]</a></font>";
			print "\t<td colspan=\"2\" align=\"center\" bgcolor=\"{$bg}\">{$link} {$del}</td>\n";
		} else {
			print "\t<td colspan=\"2\" align=\"center\" bgcolor=\"{$bg}\">{$r}</td>\n";
		}
	}
	print "</tr>\n";
}
?>
</table>
</body>
</html>
